package PTA;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;

public class Main2
{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int line=1;
		String s=null;
		ArrayList<String> T=new ArrayList<String>();
		Map<String,ArrayList> map=new HashMap();
		while(!(s=sc.nextLine()).equals("!!!!!"))
		{
			String[] str=s.split(" ");
			T.add(s);
			for (String e: str) {
				if(!map.containsKey(e))
				{
					ArrayList<Integer> list=new ArrayList<Integer>();
					list.add(line);
					map.put(e,list);
				}
				else
				{
					ArrayList<Integer> list1=new ArrayList<Integer>();
					list1=map.get(e);
					list1.add(line);
				}
		        }
			line++;
		}
		for(Map.Entry<String,ArrayList> e : map.entrySet())
		{
			System.out.println(e.getKey()+"="+e.getValue().toString());
		}
		String t=sc.nextLine();
		String[] strs=t.split(" ");
		ArrayList<Integer> List = new ArrayList<Integer>();
		
		for (int j = 1; j < strs.length; j++) {
			List.retainAll(map.get(strs[j]));
		}
		System.out.println(List.toString());
		for (int i = 0; i < List.size(); i++) {
			int count=List.get(i);
			System.out.println("Line "+count+":"+T.get(count-1));
		}
		for (int i = 0; i <map.get(sc.nextLine()).size(); i++) {
			int count=List.get(i);
			System.out.println("Line "+count+":"+T.get(count-1));
		}
	}
}